import request from '@/utils/request'

export function getList(params) {
  return request({
    url: '/table/list',
    method: 'get',
    params
  })
}

export function getaccountlist(params) {
  return request({
    url: '/table/adminlist',
    method: 'get',
    params
  })
}

export function getprojectlist(params) {
  return request({
    url: '/mproject/project',
    method: 'get',
    params
  })
}

// 未配置后台接口
export function getlogs(projectId) {
  return request({
    url: '/mproject/logs/' + projectId,
    method: 'get'
  })
}

export function getprojectinfos(projectId, pclass) {
  return request({
    url: '/mproject/project/' + projectId + '/' + pclass,
    method: 'get'
  })
}

export function postprojectinfos(projectId, pclass, data) {
  const csrftoken = document.getElementsByTagName('meta')['csrf-token'].content
  return request({
    url: '/mproject/project/' + projectId + '/' + pclass,
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json',
      'X-CSRFToken': csrftoken
    }
  })
}

export function getinfosbyid(pclass, id) {
  return request({
    url: '/mproject/byid/' + pclass + '/' + id,
    method: 'get'
  })
}

export function postinfosbyid(pclass, id, data) {
  const csrftoken = document.getElementsByTagName('meta')['csrf-token'].content
  return request({
    url: '/mproject/byid/' + pclass + '/' + id,
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json',
      'X-CSRFToken': csrftoken
    }
  })
}

export function addaccountlist(data) {
  const csrftoken = document.getElementsByTagName('meta')['csrf-token'].content
  return request({
    url: '/table/adminlist',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json',
      'X-CSRFToken': csrftoken
    }
  })
}

export function delaccountlist(username) {
  const csrftoken = document.getElementsByTagName('meta')['csrf-token'].content
  return request({
    url: '/table/adminlist/' + username,
    method: 'delete',
    headers: {
      'Content-Type': 'application/json',
      'X-CSRFToken': csrftoken
    }
  })
}

// 未配置后台接口
export function writepost(data) {
  const csrftoken = document.getElementsByTagName('meta')['csrf-token'].content
  return request({
    url: '/mproject/post',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json',
      'X-CSRFToken': csrftoken
    }
  })
}

export function addproject(data) {
  const csrftoken = document.getElementsByTagName('meta')['csrf-token'].content
  return request({
    url: '/mproject/project',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json',
      'X-CSRFToken': csrftoken
    }
  })
}
